# 原php包依赖于debian jessie
FROM php:7.3.6-fpm
MAINTAINER Jin<cpp@strcpy.cn>

# 更新镜像源
#RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
#COPY docker-file/sources.list.jessie /etc/apt/sources.list

ENV SWOOLE_VERSION 4.4.23

# 时区
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata

# 安装包
RUN apt-get update \
    && apt-get install -y libcurl4-openssl-dev \
                            libssl-dev \
                            libmcrypt-dev \
                            libpng-dev \
                            libjpeg-dev \
                            libfreetype6-dev \
                            libpng-dev \
                            libzip-dev \
                            git \
                            wget \
                            unzip
                            

RUN docker-php-ext-configure gd \
    --with-freetype-dir=/usr/include/freetype2 \
    --with-png-dir=/usr/include \
    --with-jpeg-dir=/usr/include

RUN docker-php-ext-install pdo \
                            pdo_mysql \
                            session \
                            sockets \
                            bcmath \
                            opcache \
                            calendar \
                            hash \
                            mysqli \
                            gd \
                            zip

# 安装php扩展
RUN pecl install -o -f mcrypt redis mongodb protobuf && \
    rm -rf /tmp/pear && \
    docker-php-ext-enable mcrypt redis mongodb protobuf

# 创建目录
RUN set -ex && \
    mkdir -p /var/www/app /tmp/log /var/www/cache /var/run/php7-fpm

# 设置工作目录
WORKDIR /var/www/app

# 设置目录权限
RUN chown -R www-data:www-data /tmp/log \
                                /var/www/cache \
                                /var/www/app \
                                /var/run/php7-fpm && \
    chmod -R +w /tmp/log \
                /var/www/cache \
                /var/www/app \
                /var/run/php7-fpm

# 复制配置文件
COPY docker-file/php.ini /usr/local/etc/php
COPY docker-file/php-fpm.conf /usr/local/etc/php
COPY docker-file/php-fpm.d /usr/local/etc/php-fpm.d

# 清理一下空间
RUN set -ex && \
    apt-get autoremove -y && \
    apt-get clean

# 安装swoole扩展和composer
RUN cd /tmp \
    && git clone -b v$SWOOLE_VERSION https://gitee.com/swoole/swoole.git \
    && ( \
        cd swoole \
        && phpize \
        && ./configure --enable-mysqlnd --enable-openssl --enable-http2 \
        && make -s -j$(nproc) && make install \
    ) \
    && echo "extension=swoole.so" > /usr/local/etc/php/php.ini \
    && echo "swoole.use_shortname = 'On'" >> /usr/local/etc/php/php.ini \
    && cd /tmp \
    && wget https://github.com/composer/composer/releases/download/1.8.6/composer.phar \
    && chmod u+x composer.phar \
    && mv composer.phar /usr/local/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

EXPOSE 9000